DDL
TimeBase Data Definition Language (DDL) allows to create, drop, and modify streams in TimeBase by issuing QQL statements, similar to CREATE TABLE ...
in SQL. In QQL the equivalent statement begins with CREATE ... STREAM
, and, thus, is called the Create Stream
statement.
When you create a stream, you can describe it's properties in stream OPTIONS
.
FIXEDTYPE
(boolean) - a stream capable of containing messages of a single specified type.POLYMORPHIC
(boolean) - a polymorphic stream is capable of containing messages of several specified types.LOSSLESS
(boolean) - lossless stream. Durable streams are always lossless.LOSSY
(boolean) - lossy stream.HIGHAVAILABILITY
(boolean) - high availability durable streams are cached on startup.PERIODICITY
(varchar) - indicate a known stream periodicity.DF
(numeric) - distribution factor value.INITSIZE
(numeric) - initial size of the write buffer in bytes.MAXSIZE
(numeric) - the limit on buffer growth in bytes. Default is 64K.MAXTIME
(numeric) - the limit on buffer growth as difference between first and last message time. Default is Long.MAX_VALUE.
CREATE TRANSIENT|DURABLE STREAM stream_name [title]
(class_expr|enum_expr [; ...])
[OPTIONS (identifier [= expr] [; ...])]
[COMMENT comment]
MODIFY STREAM stream_name [title]
(class_expr|enum_expr [; ...])
[OPTIONS (identifier [= expr] [; ...])]
[COMMENT comment]
[CONFIRM NO_CONVERSION|CONVERT_DATA|DROP_ATTRIBUTES|DROP_TYPES|DROP_DATA]
DROP STREAM stream_name
where classes and enumerations are described as follows:
CLASS type_name [title] [UNDER type_name]
(static_attribute|attribute [, ...])
[INSTANTIABLE|NOT INSTANTIABLE]
[COMMENT comment]
ENUM enum_name [title]
(identifier [= expr] [, ...])
[FLAGS]
[COMMENT comment]
and where static and non-statics attributes are determined as follows:
STATIC identifier [title] type [NOT NULL] [encoding] [BETWEEN min_expr AND max_expr] = expr
[TAGS (identifier:expr [, ...])]
[COMMENT comment]
identifier [title] type [NOT NULL] [encoding] [BETWEEN min_expr AND max_expr] [RELATIVE TO identifier] [DEFAULT expr]
[TAGS (identifier:expr [, ...])]
[COMMENT comment]
info
Refer to QQL Introduction for general overview.
Describe Stream
Run desc
to get stream details. You can use it to reverse-engineer an existing stream back into a QQL statement that creates it. This is called describing a stream.
DURABLE STREAM TEST (
CLASS "deltix.qsrv.hf.pub.BestBidOfferMessage" 'Quote Message' (
"offerPrice" 'Offer Price' FLOAT DECIMAL (2),
"offerSize" 'Offer Size' FLOAT DECIMAL (0),
"bidPrice" 'Bid Price' FLOAT DECIMAL (2) RELATIVE TO "offerPrice",
"bidSize" 'Bid Size' FLOAT DECIMAL (0)
);
CLASS "deltix.qsrv.hf.pub.TradeMessage" 'Trade Message' (
"price" 'Trade Price' FLOAT DECIMAL (2),
"size" 'Trade Size' FLOAT DECIMAL (0)
);
)
OPTIONS (DF = 1; HIGHAVAILABILITY = FALSE)
COMMENT 'tickquerydemo'
info
Refer to TimeBase Shell instruction.
Create Stream
You can use the desc
output to create a stream. Simply append a keyword CREATE
in front of whatever the desc
command has printed out.
tip
It is not allowed to create a stream with a duplicate key (or name), so if you want to try and create a stream just like tickquerydemo
, you have to change the key, as well.
CREATE DURABLE STREAM TEST (
CLASS "deltix.timebase.api.messages.BestBidOfferMessage" 'Quote Message' (
"offerPrice" 'Offer Price' FLOAT DECIMAL (2),
"offerSize" 'Offer Size' FLOAT DECIMAL (0),
"bidPrice" 'Bid Price' FLOAT DECIMAL (2) RELATIVE TO "offerPrice",
"bidSize" 'Bid Size' FLOAT DECIMAL (0)
);
CLASS "deltix.timebase.api.messages.TradeMessage" 'Trade Message' (
"price" 'Trade Price' FLOAT DECIMAL (2),
"size" 'Trade Size' FLOAT DECIMAL (0)
);
)
OPTIONS (DF = 1; HIGHAVAILABILITY = FALSE)
COMMENT 'QQL is awesome'
/
When you begin entering the create command into tickdb shell
, it recognizes the keyword and enters the multi-line input mode. To finish entering a multi-line command, you type a single forward slash on a separate line.
The system response looks just like the result of a SELECT
statement. This is because any statement in QQL returns a message stream, including data definition statements such as CREATE STREAM
.
Also note that the message type returned is deltix.timebase.api.messages.ErrorMessage
. This does not mean there has been an error! When the message type is SUCCESS
, it means that the activity has been completed successfully. You can just read the message text to make sure everything is alright.
tip
Remember, that if you don't enclose the new stream key in double quotes, then it will be converted to upper case, no matter how you specified it.
For example, even if you start the command with CREATE DURABLE STREAM test
, the key of the newly created stream will still be TEST
.
That is why the desc
command encloses identifiers in double quotes, unless they only contain capital letters.
Modify Stream
To modify a stream, simply append the keyword MODIFY
in front of whatever the desc
command has printed out. Specify all classes that will be present in a stream.
MODIFY STREAM TEST (
CLASS "deltix.timebase.api.messages.BestBidOfferMessage" 'Quote Message' (
"offerPrice" 'Offer Price' FLOAT DECIMAL (2),
"offerSize" 'Offer Size' FLOAT DECIMAL (0),
"offerExchange" 'Offer Exchange' VARCHAR ALPHANUMERIC (10),
"bidPrice" 'Bid Price' FLOAT DECIMAL (2) RELATIVE TO "offerPrice",
"bidSize" 'Bid Size' FLOAT DECIMAL (0),
"bidExchange" 'Bid Exchange' VARCHAR ALPHANUMERIC (10)
);
CLASS "deltix.timebase.api.messages.TradeMessage" 'Trade Message' (
"price" 'Trade Price' FLOAT DECIMAL (2),
"size" 'Trade Size' FLOAT DECIMAL (0)
);
)
OPTIONS (DF = 1; HIGHAVAILABILITY = FALSE)
COMMENT 'Modified stream' CONFIRM DROP_DATA
/
Drop Stream
Issue a drop stream
statement to remove a stream.
DROP STREAM test
tip
Drop command is single-line by default, so forward slash is not required. Also you will notice that the capitalization of the stream key is not important. That is because in all cases QQL searches for existing identifiers in a case-insensitive manner, as long as they are unambiguous.